﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Mads.CoreDomain;

namespace CassirApp
{
  public partial class TicketFin : Form
  {
    public Ticket3 t3form;

    public TicketFin(Ticket3 form)
    {
      InitializeComponent();
      t3form = form;
      ResultLabel.Hide();
    }

    private void button2_Click(object sender, EventArgs e)
    {
      foreach (FreeTicket ticket in t3form.t2form.tickets)
      {
        if (ticket.SitNumber == Int32.Parse(t3form.resultTicket))
        {
          if (t3form.t2form.t1form.client.BuyTicket(t3form.t2form.t1form.sessionId, ticket, t3form.t2form.stationDep, t3form.t2form.stationArr, FIOTextBox.Text, PassportTextBox.Text))
          {
            ResultLabel.Text = "Куплено!";
            ResultLabel.ForeColor = Color.Green;
            MessageBox.Show("Покупка успешна!");
            break;
          }
        }
      }
      if (ResultLabel.Text != "Куплено!")
      {
        ResultLabel.Text = "Не куплено!";
        ResultLabel.ForeColor = Color.Red;
        MessageBox.Show("Покупка успешна!");
      }
    }

    private void button1_Click(object sender, EventArgs e)
    {
      Close();
    }
  }
}
